<?php
// 返回json串
function json_return($status = '1',$errmsg = '',$data = false){
    if ($data === false) {
        return json_encode(array('status'=>$status,'errmsg'=>$errmsg),JSON_UNESCAPED_UNICODE);
    }else{
        return json_encode(array('status'=>$status,'errmsg'=>$errmsg,'data'=>$data),JSON_UNESCAPED_UNICODE);
    }
}

/**
 * 获取config值
 */
function get_config_by_key($key){
	$config = M("Config")->where(array("key"=>$key))->find();
	return $config['value'];
}


/**
 * 获取物流公司ID
 */
function get_logistics_ids($lid = false){
    if (!$lid) {
        $admin_id = session('ADMIN_ID');
        $user = M("users")->where(array("id"=>$admin_id,'model'=>array('in','2,7')))->find();
        if(empty($user)){
            return false;
        }
        $lid = $user['organize_id'];
    }
    
    $lid_child[] = $lid;
    $lid_child_query = M("Logistics")->where(array("manager_id"=>$lid))->field('id')->select();
    if($lid_child_query) foreach ($lid_child_query as $_key => $_row) {
        $lid_child[] = $_row['id'];
    }
    $lid_child = implode(',', $lid_child);

    return $lid_child;
}

